﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Order : IAccessible<P_Order, Order>, ILogicEntity<P_Order, Order>
    {
        public int ID { get; set; }
        public int ProjectId { get; set; }
        public decimal Amount { get; set; }
        public string OrderCode { get; set; }
        public OrderStatus Status { get; set; }
        public string UserName { get; set; }
        public DateTime CreateTime { get; set; }

        protected override void Covariant(P_Order model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.ID = model.ID;
                this.Amount = model.Amount;
                this.ProjectId = model.ProjectId;
                this.OrderCode = model.OrderCode;
                this.Status = (OrderStatus)model.Status;
                this.UserName = model.UserName;
            }
        }

        protected override P_Order Inverter(Order model)
        {
            if (model != null)
            {
                return new P_Order()
                {
                    CreateTime = model.CreateTime,
                    ID = model.ID,
                    Amount = model.Amount,
                    ProjectId = model.ProjectId,
                    OrderCode = model.OrderCode,
                    Status = (int)model.Status,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public Order Set(P_Order dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
